/**
 * 服务器交互
 */

define(function (require, exports, module) {
    var aw = require("ajaxwrapper");
    var moment = require("moment");
    module.exports = {
    	
    	saveSignup:function(formData,callback){
    		var data = {
    			pkPlanItem: formData.pkPlanItem,
    			pkServicePoint: formData.pkServicePoint,
    			signUpRegister:[]
    		}
    		var signUpRegister = [];
    		
    		var isMember = formData.member == "true" ? true:false;
    		
    		if(!isMember){
    			signUpRegister.push({
    				"member":formData.member,
    				"pkSignUpRegister":formData.pkSignUpRegister,
    				"version":formData.version,
    				"signUpDate":moment(formData.signUpDate).format("x"),
    				"personalInfo.name":formData["personalInfo.name"],
    				"personalInfo.mobilePhone":formData["personalInfo.mobilePhone"],
    				"personalInfo.idNumber":formData["personalInfo.idNumber"],
    				"personalInfo.sex":formData["personalInfo.sex"],
    				"travelContract.pkTravelContract":formData["pkTravelContract"]
    			});    			
    		}else{
    			
    			signUpRegister.push({
    				"pkSignUpRegister":formData.pkSignUpRegister,
    				"version":formData.version,
    				"member":formData.member,
    				"signUpDate":moment(formData.signUpDate).format("x"),
    				"personalInfo.pkPersonalInfo":formData["personalInfo.pkPersonalInfo"],
    				"personalInfo.version":formData["personalInfo.version"],
    				"travelContract.pkTravelContract":formData["pkTravelContract"]
    			});	
    		}
    		data.signUpRegister = signUpRegister;
    		
    		data = aw.customParam(data);
    		
    		aw.saveOrUpdate("api/signupregister/saveall",data,function(data){
    			callback(data);
			});
    	},
    	
    	saveRoomInfo:function(data){
    		aw.saveOrUpdate("api/planitemgroup/save",data,function(data){
    			widget.hide([".J-form", ".J-applygrid",".J-detailgrid"]).show([".J-grid",".J-editgrid"]);
				widget.get("subnav").hide(["save", "cancel"]).show(["travelDate", "destination", "servicePoint","payFul"]);
				widget.get("form").reset();
				widget.get("grid").refresh();
			});
    	}
    	
    };
});
